package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.Appointment;
import cn.hl.sfzy.entity.User;
import cn.hl.sfzy.entity.UserMark;
import cn.hl.sfzy.mapper.AppointmentMapper;
import cn.hl.sfzy.mapper.UserMapper;
import cn.hl.sfzy.mapper.UserMarkMapper;
import cn.hl.sfzy.service.UserMarkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserMarkServiceImpl
 * @Description TODO
 * @Author LiuYao
 * @Date 2024年10月24日 11:48
 * @Version 1.0
 */
@Service
public class UserMarkServiceImpl implements UserMarkService {
    @Autowired
    private UserMarkMapper userMarkMapper;
    @Autowired
    private AppointmentMapper appointmentMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public int remove(Long id) {
        return userMarkMapper.delete(id);
    }

    @Override
    public PageInfo findByPage(Integer pageNum, Integer pageSize, UserMark userMark) {
        PageHelper.startPage(pageNum,pageSize);
        List<UserMark> list= userMarkMapper.select(userMark);
        for(UserMark at : list){
            Appointment appointment = appointmentMapper.selectById(at.getApp_id());
            User user=userMapper.selectById(at.getUser_id());
            at.setUser(user);
            at.setAppointment(appointment);
        }
        PageInfo<UserMark> pageInfo=new PageInfo(list);
        return pageInfo;
    }

    @Override
    public int deleteByUserId(Long user_id) {
        int i = userMarkMapper.deleteByUserId(user_id);
        return i;
    }
}
